from flask import Flask,request,Response,jsonify
from user import db,Users,app


@app.route('/users')
def get_users():
    users = Users.query.all()  # 查询所有用户
    print(users)
    return jsonify([(u.username,u.email) for u in users])

# @app.route('/add_user', methods=['POST'])
# def add_user():
#     data = request.json
#     new_user = Users(name=data['name'], email=data['email'])
#     db.session.add(new_user)
#     db.session.commit()  # 提交事务
#     return {'message': 'User created'}, 201

# 原生SQL执行（需要时使用）
# @app.route('/custom_query')
# def custom_query():
#     result = db.session.execute("SELECT * FROM users ")
#     return {'data': [dict(row) for row in result]}


if __name__ == '__main__':
    app.run(debug=True)